import axios from "axios";
//引入进度条
import nProgress from "nprogress";
//start:进度条开始 done:进度条结束
//引入进度条的样式
import "nprogress/nprogress.css"
// 从仓库又引入uuid
import store from '@/store'
//配置axios
const requests = axios.create({
    baseURL: "/api",
    //请求响应超时
    timeout: 5000,
});
//请求拦截器
requests.interceptors.request.use((config) => {
    // 在请求头里面进入uuid和token
    if (store.state.detail.uuid_token) {
        config.headers.userTempId = store.state.detail.uuid_token
    }
    console.log(store.state.login.token);
    if (store.state.login.token) {
        console.log(1);
        config.headers.token = store.state.login.token
    }
    nProgress.start()
    return config
})

//响应拦截器
requests.interceptors.response.use((res) => {
    nProgress.done()
    return res.data
}, (error) => {
    return Promise.reject(new Error('faile'))
})
export default requests